home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 August: Tool Chest / Dev.CD Aug 98 TC.toast / Tool Chest / Testing & Debugging / Virtual User / Virtual User Current Release / Examples / Example External Tools / ProcessTool / ProcessTool Sample.vu < prev    next >
Encoding:
Text File  |  1998-06-04  |  3.6 KB  |  102 lines  |  [TEXT/MPS ]

  1. #
  2. #    File:        ProcessTool Sample.vu
  3. #
  4. #    Contents:    ProcessTool example usages.
  5. #
  6. #    Copyright © 1992 Apple Computer, Inc.  All rights reserved.
  7. #
  8.  
  9. Libraries "ProcessTool.vulib";
  10.  
  11. script ProcessToolSample()
  12. begin
  13.     
  14.      (* Results returned by external tool services are in the form of a 2- or 3-item list:
  15.         { errorCode, returnedValue, optionalErrorString }
  16.     The errorCode will be zero if the call succeeded.
  17.     So the success or failure of the call can be found in item 1 of the list,
  18.     the returnedValue (whether a number or string or list itself) in item 2,
  19.     and an optional error string in item 3.
  20.     If the list does not include the error string, accessing item 3 will return undefined.
  21.     The task ReturnErrorString below checks for the existence of the error string. *)
  22.     
  23.     
  24.     m := ProcessTool( "Initialize", TRUE );                # Initialize the ProcessTool on the TARGET.
  25. #        if m[1] <> 0                                    # If error during initialization,
  26. #        begin
  27. #            println "ProcessTool could not be initialized";        # print error
  28. #            println "Error ", m[1], ". ", ReturnErrorString( m[3] );
  29. #            exit;                                        # & exit this script.
  30. #        end;
  31.     
  32.     println "Getting list of current processes:";
  33.     m := ProcessTool( "ProcessNamesList" );                # Get list of process names.
  34.     if m[1] = 0                                            # If no error,
  35.     begin
  36.         processList := m[2];                            # copy the returnedValue, the process list.
  37.         println processList;                            # & print the processList.
  38.     end;
  39.     else
  40.         println "Error ", m[1], " occurred. ", ReturnErrorString( m[3] );    # else print error.
  41.     
  42.     println;
  43.     
  44.     println "Getting name of front process:";
  45.     m := ProcessTool("FrontProcessName" );                # Get front process name.
  46.     if m[1] = 0                                            # If no error,
  47.         println m[2];                                    # print the front process name.
  48.     else
  49.         println "Error ", m[1], " occurred. ", ReturnErrorString( m[3] );    # else print error.
  50.     
  51.     println;
  52.     
  53.     println "Getting partition size and free memory of all active processes:";
  54.     for i := 1 to card processList                        # Loop through items of processList:
  55.     begin
  56.         m := ProcessTool( "PartitionSize", processList[i] );    # Get partition size
  57.         if m[1] = 0
  58.             println "Partition size of ", processList[i], " is ", m[2];
  59.         else
  60.             println "PartitionSize of ", processList[i], " error ", m[1], " occurred. ", ReturnErrorString( m[3] );
  61.         m := ProcessTool( "FreeMem", processList[i] );            # Get free memory
  62.         if m[1] = 0
  63.             println "Free Memory for ", processList[i], " is ", m[2];
  64.         else
  65.             println "FreeMem of ", processList[i], " error ", m[1], " occurred. ", ReturnErrorString( m[3] );
  66.     end;
  67.     
  68.     println;
  69.     
  70.     println "Read a single byte:";
  71.     m := ProcessTool( "ReadByte", 16384 );                # (small address uses regular V.U. number) 
  72.     if m[1] = 0
  73.         println "The byte stored at address 16384 is ", m[2];
  74.     else
  75.         println "ReadByte error ", m[1], " occurred. ", ReturnErrorString( m[3] );
  76.     
  77.     println;
  78.     
  79.     println "Read a block of bytes into a list:";
  80.     m := ProcessTool( "ReadBlock", '65536', 10 );        # (large address uses quoted number string)
  81.     if m[1] = 0
  82.         println "The 10 bytes stored starting at address 65536 are in the list: ", m[2];
  83.     else
  84.         println "ReadBlock error ", m[1], " occurred. ", ReturnErrorString( m[3] );
  85.  
  86. end;
  87.  
  88.  
  89.  
  90. (* External tools return a list with an OPTIONAL error string in the 3rd position.
  91.     If there is no optional error string, then accessing that item in the list (m[3])
  92.     will return undefined.  This task check the given entry.  If it's undefined, then
  93.     the task replaces it with the empty string.  That simplifies error handling:  If
  94.     there IS an error string, it is printed.  If there is NOT, nothing is printed. *)
  95.     
  96. task ReturnErrorString( errorStringEntry )
  97. begin
  98.     if IsUndefined( errorStringEntry )
  99.         return "";
  100.     else
  101.         return errorStringEntry;
  102. end;